// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

export async function add(body: DISCOUNT.Coupon) {
  return request<DISCOUNT.Coupon>('/api/discount/coupon/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
  });
}

/** 获取当前的用户 GET /api/coupon/list */
export async function list(params: {
  // query
  /** 当前的页码 */
  current?: number;
  /** 页面的容量 */
  pageSize?: number;
}) {
  params.current = params.current ? params.current - 1 : 0;
  const response = await request<{
    data: DISCOUNT.CouponList;
  }>('/api/discount/coupon/list', {
    method: 'GET',
    params: {
      ...params,
    },
  });
  return {
    data: response.data?.content,
    success: true,
    total: response.data?.totalElements,
  };
}

export async function updateStatus(body: { id?: number; status: number }) {
  return request<DISCOUNT.Coupon>('/api/discount/coupon/updateStatus', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
  });
}
